package com.example.mykotilin.paging2

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.AbstractSavedStateViewModelFactory
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import com.example.mykotilin.R
import com.example.mykotilin.databinding.ActivityRedditMainBinding
import com.example.mykotilin.paging2.repository.RedditPostRepository

class RedditMainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityRedditMainBinding;


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //布局绑定
        binding = ActivityRedditMainBinding.inflate(layoutInflater);
        setContentView(binding.root)

        binding.withDatabase.setOnClickListener {
            show(RedditPostRepository.TYPE.DB);//类型跳转，数据库
        }
        binding.networkOnly.setOnClickListener {
            show(RedditPostRepository.TYPE.IN_MEMORY_BY_ITEM) //item
        }
        binding.networkOnlyWithPageKeys.setOnClickListener {
            show(RedditPostRepository.TYPE.IN_MEMORY_BY_PAGE) //页码
        }
    }

    //进行跳转
    private fun show(type: RedditPostRepository.TYPE) {
        val intent = RedditActivity.intentFor(this, type)
        startActivity(intent)
    }


}